package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.LearningContent;
import com.ruoyi.system.mapper.LearningContentMapper;
import com.ruoyi.system.service.ILearningContentService;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用来发布学习内容Service业务层处理
 * 
 * @author admin
 * @date 2024-03-06
 */
@Service("contentService")
public class LearningContentServiceImpl implements ILearningContentService 
{
    @Autowired
    private LearningContentMapper learningContentMapper;

    @Autowired
    private ISysUserService userService;

    /**
     * 查询用来发布学习内容
     * 
     * @param contentId 用来发布学习内容主键
     * @return 用来发布学习内容
     */
    @Override
    public LearningContent selectLearningContentByContentId(Long contentId)
    {
        LearningContent learningContent = learningContentMapper.selectLearningContentByContentId(contentId);
        SysUser sysUser = userService.selectUserById(Long.valueOf(learningContent.getCreatorId()));
        learningContent.setCreatorName(sysUser.getUserName());
        return learningContent;
    }

    /**
     * 查询用来发布学习内容列表
     * 
     * @param learningContent 用来发布学习内容
     * @return 用来发布学习内容
     */
    @Override
    public List<LearningContent> selectLearningContentList(LearningContent learningContent)
    {
        List<LearningContent> learningContents = learningContentMapper.selectLearningContentList(learningContent);
        for (LearningContent content : learningContents) {
            SysUser sysUser = userService.selectUserById(Long.valueOf(content.getCreatorId()));
            content.setCreatorName(sysUser.getUserName());
        }
        return learningContents;
    }

    /**
     * 新增用来发布学习内容
     * 
     * @param learningContent 用来发布学习内容
     * @return 结果
     */
    @Override
    public int insertLearningContent(LearningContent learningContent)
    {
        return learningContentMapper.insertLearningContent(learningContent);
    }

    /**
     * 修改用来发布学习内容
     * 
     * @param learningContent 用来发布学习内容
     * @return 结果
     */
    @Override
    public int updateLearningContent(LearningContent learningContent)
    {
        learningContent.setUpdateTime(DateUtils.getNowDate());
        return learningContentMapper.updateLearningContent(learningContent);
    }

    /**
     * 批量删除用来发布学习内容
     * 
     * @param contentIds 需要删除的用来发布学习内容主键
     * @return 结果
     */
    @Override
    public int deleteLearningContentByContentIds(String contentIds)
    {
        return learningContentMapper.deleteLearningContentByContentIds(Convert.toStrArray(contentIds));
    }

    /**
     * 删除用来发布学习内容信息
     * 
     * @param contentId 用来发布学习内容主键
     * @return 结果
     */
    @Override
    public int deleteLearningContentByContentId(Long contentId)
    {
        return learningContentMapper.deleteLearningContentByContentId(contentId);
    }
}
